﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using Utilities;

namespace Configurations
{
    public class Configs
    {
        public static string FileName
        {
            get
            {
                return ConfigurationManager.AppSettings["FileName"];
            }
            set
            {
                System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                config.AppSettings.Settings["FileName"].Value = value;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("appSettings");
            }
        }

        public static string FileDirectory
        {
            get
            {
                return ConfigurationManager.AppSettings["FileDirectory"];
            }
            set
            {
                System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                config.AppSettings.Settings["FileDirectory"].Value = value;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("appSettings");
            }
        }

        public static string Password
        {
            get
            {
                return ConfigurationManager.AppSettings["Password"];
            }
            set
            {
                System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                string pass = value;
                config.AppSettings.Settings["Password"].Value = DataUtil.GetMD5(pass);
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("appSettings");
            }
        }

        public static bool IsFirtTime
        {
            get
            {
                return DataUtil.ToBool(ConfigurationManager.AppSettings["IsFirtTime"]);
            }
            set
            {
                System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                bool pass = value;
                config.AppSettings.Settings["IsFirtTime"].Value = pass.ToString();
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("appSettings");
            }
        }

        static Configs()
        {
        }
    }
}
